import android.graphics.Color
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bawei.image.ImgOptions
import com.bawei.image.LoadImageUtil

/**
 * 绑定适配器对象
 */

object CommonBindingAdapter {

    @JvmStatic
    @BindingAdapter("imageUrl")
    fun loadUrlImage(imageView: ImageView, url:String){
        if (!url.isNullOrEmpty()){
            LoadImageUtil.loadUrl(imageView.context, url, imageView)
        }

    }

    @JvmStatic
    @BindingAdapter("imageCircleUrl")
    fun loadUrlCircleImage(imageView: ImageView, url:String){
        if (!url.isNullOrEmpty()){
            var options = ImgOptions.Builder.isCircle(true).build()
            LoadImageUtil.loadUrl(imageView.context, url, imageView, options)
        }
    }

    @JvmStatic
    @BindingAdapter("bgColor")
    fun loadBgColor(imageView: ImageView, colorStr: String){
        if (!colorStr.isNullOrEmpty()){
            imageView.setBackgroundColor(Color.parseColor(colorStr))
        }
    }


}